//
//  ClubTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/9.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ClubTableViewCell.h"

@interface ClubTableViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, strong)UIImageView * oneImageView;
//@property (nonatomic, strong)UIImageView * twoImageView;
//@property (nonatomic, strong)UIImageView * threeImageView;
//@property (nonatomic, weak)UILabel * topLabel;
@property (nonatomic, weak)UILabel * readNumLabel;
@property (nonatomic, weak)UILabel * personLabel;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation ClubTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setModel:(ClubModel *)model{
    
    _model = model;
    
    self.titleLabel.text = model.title;
    
    NSString * str = model.images.firstObject;
    NSURL * url = [NSURL URLWithString:str];
    [self.oneImageView sd_setImageWithURL:url];
    
    NSDictionary * dict = model.user;
    self.personLabel.text = dict[@"username"];
    
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.text = @"阿斯蒂芬哪怕是萨拉热地方";
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    self.oneImageView = [self setupImageView];
    [self.contentView addSubview:self.oneImageView];
    
//    self.twoImageView = [self setupImageView];
//    [self.contentView addSubview:self.twoImageView];
//
//    self.threeImageView = [self setupImageView];
//    [self.contentView addSubview:self.threeImageView];
    
//    UILabel * topLabel = [UILabel new];
//
//    topLabel.textColor = [UIColor redColor];
//    topLabel.layer.borderColor = [[UIColor redColor] CGColor];
//    topLabel.layer.borderWidth = 1.0f;
//    topLabel.text = @" 置顶 ";
//    topLabel.font = [UIFont systemFontOfSize:10 * SCREENH6];
//
//    self.topLabel = topLabel;
//
//    [self.contentView addSubview:self.topLabel];
    
    
    UILabel * personLabel = [UILabel new];
    
    personLabel.textColor = [UIColor lightGrayColor];//ColorWithRGB(0xe6e6e6);
    personLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    personLabel.text = @"来自人民日报";
    
    self.personLabel = personLabel;
    
    [self.contentView addSubview:self.personLabel];
    
    
    UILabel * readNumLabel = [UILabel new];
    
    readNumLabel.textColor = [UIColor lightGrayColor];//ColorWithRGB(0xe6e6e6);
    readNumLabel.font = [UIFont systemFontOfSize:12 * SCREENH6];
    readNumLabel.text = @"10068阅读";
    
    self.readNumLabel = readNumLabel;
    
    [self.contentView addSubview:self.readNumLabel];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
 
}

- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(10 * SCREENH6);
    }];
    
    [self.oneImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.titleLabel);
//        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
//        make.width.mas_equalTo(115 * SCREENH6);
        make.height.mas_equalTo(200 * SCREENH6);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
//    [self.twoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.oneImageView.mas_trailing).offset(3 * SCREENH6);
//        make.width.height.centerY.mas_equalTo(self.oneImageView);
//    }];
//
//    [self.threeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.twoImageView.mas_trailing).offset(3 * SCREENH6);
//        make.width.height.centerY.mas_equalTo(self.twoImageView);
//    }];
    
//    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.oneImageView);
//        make.top.mas_equalTo(self.oneImageView.mas_bottom).offset(6 * SCREENH6);
//    }];
    
    [self.personLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneImageView);
        make.top.mas_equalTo(self.oneImageView.mas_bottom).offset(6 * SCREENH6);
    }];
    
    [self.readNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.personLabel.mas_trailing).offset(8 * SCREENH6);
        make.centerY.mas_equalTo(self.personLabel);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}


- (UIImageView *)setupImageView{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.backgroundColor = [UIColor lightGrayColor];
    
    return imageView;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
